﻿using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using XnaCanvas;
using matrix = Microsoft.Xna.Framework.Matrix;
using math = Microsoft.Xna.Framework.MathHelper;
using Microsoft.Xna.Framework.Graphics;

namespace Test.Scenes {
    public partial class XnaBase2DTest1 : UserControl {
        public XnaBase2DTest1() {
            InitializeComponent();
        }
        XObj3 xo;
        XSence xs;
        //Model mm;
        private void UserControl_Loaded(object sender, RoutedEventArgs e) {
            xs = xcanvas.Children[xcanvas.Trigger.Csn];
            //xs.InitialCamera(10);
            this.xcanvas.Trigger.FrameRefresh += Trigger_FrameRefresh;
            //this.xcanvas.Trigger.MouseEnterState += Trigger_MouseEnterState;
            xo = new XObj3();
            xcanvas.Trigger.Rs.FillMode = Microsoft.Xna.Framework.Graphics.FillMode.WireFrame;
            //xcanvas.Trigger.Rs.CullMode = Microsoft.Xna.Framework.Graphics.CullMode.None;
            xs.Add("aaa", xo);
            xo.SetColor(100, 200, 150, 200);
            xo.effect.EnableDefaultLighting();
            xo.effect.PreferPerPixelLighting = true;
            xo.effect.LightingEnabled = true;
            //xo.effect.Alpha = 1.0f;
            //xo.effect.AmbientLightColor = new Vector3(10, 10, 10);
            var anglescount = 8;
            var angles = new float[anglescount];
            for (int i = 0; i < anglescount; i++) {
                angles[i] = i * MathHelper.TwoPi / anglescount;
            }
            xo.LoadParallelPolyhedronPrimitive(y => 1, h => 1+.8f * (float)Math.Cos(h), angles, new[] { 0.0f, 2.0f ,3.5f});
            //xo.LoadParallelPolyhedronPrimitive();
            this.xcanvas.Begin();
        }

        void Trigger_FrameRefresh(XTrigger sender) {
            //在这里 写 xo的 旋转
            xo.World *= matrix.CreateRotationX(.03f);
            xo.World *= matrix.CreateRotationY(.03f);
            xo.World *= matrix.CreateRotationZ(.03f);
        }
    }
}
